home *** CD-ROM | disk | FTP | other *** search
/ Inter.Net 55-1 / Inter.Net 55-1.iso / CBuilder / Info / TeachU14 / SAMS / Code / Day02 / maillist.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1998-02-08  |  2.2 KB  |  96 lines

  1. //---------------------------------------------------------------------------
  2. #include <condefs.h>
  3. #include <iostream.h>
  4. #include <conio.h>
  5. #pragma hdrstop
  6.  
  7. #include "structur.h"
  8. //---------------------------------------------------------------------------
  9.  
  10. void displayRecord(int, mailingListRecord mlRec);
  11.  
  12. int main(int, char**)
  13. {
  14.   //
  15.   // create an array of mailingListRecord structures
  16.   //
  17.   mailingListRecord listArray[3];
  18.   cout << endl;
  19.   int index = 0;
  20.  
  21.   // get three records
  22.   //
  23.   do {
  24.     cout << "First Name: ";
  25.     cin.getline(listArray[index].firstName,
  26.       sizeof(listArray[index].firstName) - 1);
  27.     cout << "Last Name: ";
  28.     cin.getline(listArray[index].lastName,
  29.       sizeof(listArray[index].lastName) - 1);
  30.     cout << "Address: ";
  31.     cin.getline(listArray[index].address,
  32.       sizeof(listArray[index].address) - 1);
  33.     cout << "City: ";
  34.     cin.getline(listArray[index].city,
  35.       sizeof(listArray[index].city) - 1);
  36.     cout << "State: ";
  37.     cin.getline(listArray[index].state,
  38.       sizeof(listArray[index].state) - 1);
  39.     char buff[10];
  40.     cout << "Zip: ";
  41.     cin.getline(buff, sizeof(buff) - 1);
  42.     listArray[index].zip = atoi(buff);
  43.     index++;
  44.     cout << endl;
  45.   }
  46.   while (index < 3);
  47.   //
  48.   // clear the screen
  49.   //
  50.   clrscr();
  51.   //
  52.   // display the three records
  53.   //
  54.   for (int i=0;i<3;i++) {
  55.     displayRecord(i, listArray[i]);
  56.   }
  57.   //
  58.   // ask the user to choose a record
  59.   //
  60.   cout << "Choose a record: ";
  61.   int rec;
  62.   //
  63.   // be sure only 1, 2, or 3 was selected
  64.   //
  65.   do {
  66.     rec = getch();
  67.     rec -= 49;
  68.   } while (rec < 0 || rec > 2);
  69.   //
  70.   // assign the selected record to a temporary variable
  71.   //
  72.   mailingListRecord temp = listArray[rec];
  73.   clrscr();
  74.   cout << endl;
  75.   //
  76.   // display the selected recrord
  77.   //
  78.   displayRecord(rec, temp);
  79.   getch();
  80.   return 0;
  81. }
  82. void displayRecord(int num, mailingListRecord mlRec)
  83. {
  84.   cout << "Record " << (num + 1) << ":" << endl;
  85.   cout << "Name:     " << mlRec.firstName << " ";
  86.   cout << mlRec.lastName;
  87.   cout << endl;
  88.   cout << "Address:  " << mlRec.address;
  89.   cout << endl << "          ";
  90.   cout << mlRec.city << ", ";
  91.   cout << mlRec.state << "  ";
  92.   cout << mlRec.zip;
  93.   cout << endl << endl;
  94. }
  95.  
  96.